<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>非上市公司指数管理</title>
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <style type="text/css">
    .searcheBottom{margin-bottom: 10px;}
    </style>
</head>

<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
    <form>
        <div class="demoTable">
         <div class="layui-inline searcheBottom">
       		  平台名称：
            <div class="layui-inline">
                <input id="platformName" class="layui-input" name="platformName" autocomplete="off" placeholder="请输入平台名称" />
            </div>
            </div>
            <div class="layui-inline searcheBottom">
       		  企业名称：
            <div class="layui-inline">
                <input id="enterpriseName" class="layui-input" name="enterpriseName" autocomplete="off" placeholder="请输入企业名称" />
            </div>
            </div>
            <div class="layui-inline searcheBottom">
                             状态：
            <div class="layui-inline">
                <select  id="enableFlag" name="enableFlag" class="layui-input" style="padding: 0px 20px;">
                    <option value="" selected>---请选择---</option>
                    <option value="1">使用中</option>
                    <option value="0">已下架</option>
                </select>
            </div>
            </div>
            
            <div class="layui-inline searcheBottom">
            <button type="button" class="layui-btn" data-type="reload" id="search">搜索</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <a href="/manage/index/nonListedCompanyIndexAdd" class="layui-btn addChannel" id="add">
                <i class="layui-icon">&#xe608;</i> 新增指数
            </a>
            </div>
        </div>
        </form>
    </blockquote>
        <span style="font-size: 16px;"><b>非上市公司指数列表</b></span>
        <table class="layui-hide" id="tableId" lay-filter="tableFilter">
        </table>
    
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/plugins/layui/lay/modules/util.js"></script>
<script type="text/javascript" src="/js/utils.js"></script>
<script>
layui.config({
	  version: '1515376178709', //为了更新 js 缓存，可忽略
      base: '/js/'
	});
	 
	layui.use(['laydate', 'layer', 'table', 'form', 'element','util'], function(){
	  var laydate = layui.laydate //日期
	  ,laypage = layui.laypage //分页
	  ,layer = layui.layer //弹层
	  ,table = layui.table //表格
	  ,carousel = layui.carousel //轮播
	  ,upload = layui.upload //上传
	  ,element = layui.element//元素操作
	  ,util = layui.util
	  ,$=layui.jquery
	  //监听Tab切换
	  element.on('tab(tableFilter)', function(data){
	    layer.msg('切换了：'+ this.innerHTML);
	    console.log(data);
	  });
	  
	  //执行一个 table 实例
	  var tableIns=table.render({
	    elem: '#tableId'
	    ,url: '/manage/index/listNonListedCompanyIndex' //数据接口
	    ,page: true //开启分页
	    ,cols: [[ //表头
	      {field: 'id', title: 'ID', sort: true, fixed: 'left',width:100}
	      ,{field: 'platformName', title: '平台名称',sort: true}
	      ,{field: 'enterpriseName', title: '企业名称',sort: true}
	      ,{field: 'onlineTime', title: '上线时间', sort: true,width:170,templet: function(d){
	        if(d.onlineTime !=null){
                return util.toDateString(d.onlineTime,'yyyy-MM-dd HH:mm:ss')
            }else {
	            return '';
            }
	      }}
	      ,{field: 'cityName', title: '所在城市',sort: true}
	      ,{field: 'index', title: '指数',sort: true}
	      ,{field: 'enableFlag', title: '状态', sort: true,width:100,templet: function(d){
	          if(d.enableFlag=='0'){
	        	  return  '<div class="layui-btn layui-btn-xs layui-btn-danger">已下架</div>'
	          }else{
	        	  return '<div class="layui-btn layui-btn-xs">使用中</div>'
	          }
	      }}
	      ,{title:"操作", align:'left',templet: function(d){
	    	  if(d.enableFlag=='1'){
	    		  return '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>'
	    			+'<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">下架</a>';
	    	  }else{
	    		  return '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>'
	    			+'<a class="layui-btn layui-btn-xs" style="background-color: #01aaed" lay-event="add">上架</a>';
	    	  }
	    		 
	      }}
	    ]]
	  });
	  
	  //搜索
	  $("#search").on("click",function(){
		  tableIns.reload({
				where: {
				    "platformName":platformName.value,
				    "enterpriseName":enterpriseName.value,
				    "enableFlag":enableFlag.value,
				}
				,page: {
				 curr: 1 //重新从第 1 页开始
				  }
			  }); 
	  });

        $(".layui-input").keydown(function (e) {
            if(e.keyCode == 13){
                $('#search').click();
            }
        });

        //监听工具条
	  table.on('tool(tableFilter)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
	    var data = obj.data //获得当前行数据
	    ,layEvent = obj.event; //获得 lay-event 对应的值
	    if(layEvent === 'del'){
	      layer.confirm('确定提交么', function(index){
	        //向服务端发送删除指令
	        updateEnableFlag(data.id,false,'下架成功！')
	      return false;
	      });
	    } else if(layEvent === 'edit'){
	      location.href="/manage/index/nonListedCompanyIndexEdit?id="+data.id
	    } else if(layEvent === 'add'){
	    	layer.confirm('确定提交么', function(index){
		        //向服务端发送删除指令
		        updateEnableFlag(data.id,true,'上架成功！')
		      return false;
		      });
	    }
	   });
	  
	  function updateEnableFlag(id,enableFlag,msg){
			//向服务端发送删除指令
	          $.ajax({
	            type : "POST",
	            url : "/manage/index/updateEnableFlag",
	            dataType : "json",
	            data :{"id":id,"enableFlag":enableFlag,"msg":msg},
	            success : function(resData) {
	          	  layer.alert(resData.msg, {
	          		    skin: 'layui-layer-molv' //样式类名  自定义样式
	          		    ,closeBtn: 1    // 是否显示关闭按钮
	          		    ,anim: 1 //动画类型
	          		    ,btn: ['确定'] //按钮
	          		    ,icon: 1    // icon
	          		    ,yes:function(){
	          		    	if (resData.code >= 0) {
	          	                  location.href = "/manage/index/nonListedCompanyIndexList";
	          	              }
	          		    }});
	            },
	            error : function() {
	                alert("系统异常,请稍后重试");
	            }
	        });
		  }
	  
	});
</script>
</body>

</html>